#'
#' Remove trait from the community object
#' 
#' @param com a community object
#' @param traitnames a vector of trait names
#'
#'@examples
#'
#'com=rcommunity(splist=c("sp1","sp2"),abundance=c(10,20),plotdim=c(100,100),traits=data.frame(dbh=runif(30)))
#'
#'remove_traits(com,"dbh")
#'
#' @export
remove_traits=function(da,traitnames){
  UseMethod("remove_traits")
}

#' @export
remove_traits.population=function(pop,traitnames){
  deli=match(traitnames,get_trait_names(pop))+2
  if(all(is.na(deli))){
    warning("no corresponding trait names have been found")
    return(pop)
  }else if(any(!is.na(deli))){
    if(any(is.na(deli))) warning("some trait names were not found")
    
    deli=deli[!is.na(deli)]
    return(pop[,-deli])
  }
}



#' @export
remove_traits.community=function(com,traitnames){
  deli=match(traitnames,get_trait_names(com))+3
  if(all(is.na(deli))){
    warning("no corresponding trait names have been found")
    return(com)
  }else if(any(!is.na(deli))){
    if(any(is.na(deli))) warning("some trait names were not found")
    
    deli=deli[!is.na(deli)]
    return(com[,-deli])
  }
}

